//
//  LearnCellHome.m
//  Cunli
//
//  Created by lilubin on 15/7/7.
//  Copyright (c) 2015年 lilubin. All rights reserved.
//

#import "LearnCellHome.h"
#import "LearnModel.h"
#import "UIImageView+WebCache.h"
#import "DeviceInfoClass.h"

@implementation LearnCellHome

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    NSURL *picURL = [NSURL URLWithString:_learnModel.pic];
    [_titleImgView setImageWithURL:picURL placeholderImage:[UIImage imageNamed:@"default_news"]];
    
    _titleLabel.text = _learnModel.title;
    _authorLabel.text = _learnModel.auOrSper;
    _introduceLabel.text = _learnModel.introduce;
    _typeLabel.textAlignment = NSTextAlignmentCenter;
    
    if (_learnModel.modelType == LearnModelTypeAuthor) {
        _typeLabel.text = @"普法教材";
        [_typeLabel setBackgroundColor:[UIColor colorWithHexString:@"0x2fc14e"]];
    }
    else if(_learnModel.modelType == LearnModelTypeSpeaker){
        [_typeLabel setBackgroundColor:[UIColor colorWithHexString:@"0x2fa9f4"]];
        _typeLabel.text = @"普法讲堂";
    }
    else
    {
        [_typeLabel setBackgroundColor:[UIColor colorWithHexString:@"0x2fa9f4"]];
        _typeLabel.text = @"法律法规";
    }
    
    [_titleLabel setTextColor:[UIColor colorWithHexString:InfoCellTitleColorValue]];
    [_authorLabel setTextColor:[UIColor colorWithHexString:InfoCellIntroduceColorValue]];
    [_introduceLabel setTextColor:[UIColor colorWithHexString:InfoCellIntroduceColorValue]];
    
    if ([DeviceInfoClass getCurrentDeviceDetailVersion] == DeviceInfoVersioniPhone4s || [DeviceInfoClass getCurrentDeviceDetailVersion] == DeviceInfoVersioniPhone5s) {
        [_titleLabel setFont:[UIFont systemFontOfSize:16.0f]];
        [_introduceLabel setFont:[UIFont systemFontOfSize:13.0f]];
        [_authorLabel setFont:[UIFont systemFontOfSize:13.0f]];
    }
}

- (void)setLearnModel:(LearnModel *)learnModel
{
    if (_learnModel != learnModel) {
        _learnModel = learnModel;
        NSURL *picURL = [NSURL URLWithString:_learnModel.pic];
        [_titleImgView setImageWithURL:picURL placeholderImage:[UIImage imageNamed:@"default_news"]];
        
        _titleLabel.text = _learnModel.title;
        _authorLabel.text = _learnModel.auOrSper;
        _introduceLabel.text = _learnModel.introduce;
    }
}
@end
